package com.dahafo.bootnews;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.List;

@Slf4j
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        ApplicationContext context=SpringApplication.run(Application.class, args);

        Binder binder=Binder.get(context.getEnvironment());
        FooProperties foo=binder.bind("com.dahafo", Bindable.of(FooProperties.class)).get();

        log.info(foo.getFoo());

        List<String> post=binder.bind("com.dahafo.post", Bindable.listOf(String.class)).get();
        log.info(post.toString());

        List<PostInfo> posts=binder.bind("com.dahafo.posts", Bindable.listOf(PostInfo.class)).get();

        log.info(posts.toString());


    }

    @Bean
    public DataLoader dataLoader(){
        return new DataLoader();
    }

    @Slf4j
    static class DataLoader implements CommandLineRunner{

        @Override
        public void run(String... args) throws Exception {
            log.info("Loading data...");
        }
    }

}
